package com.lyt.springboot.controller;

import com.lyt.springboot.dao.BookRepository;
import com.lyt.springboot.domain.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/books")
public class BookController {

    @Autowired
    private BookRepository bookRepository;

    @PostMapping
    public Book createBook(@RequestBody Book book) {
        return bookRepository.save(book);
    }

    @GetMapping("/{id}")
    public Book getBook(@PathVariable String id) {
        return bookRepository.findById(id).orElse(null);
    }
}